package com.panasonic.mes.management.util;

import java.text.DecimalFormat;

/**
 * DailyBeanUtil:稼动日报展示与导出使用
 * 
 * @author kk-quyunde
 * @date 2022-01-11
 *
 */
public class FormatUtil {

//	public static void main(String[] args) {
//		System.out.println(numberFormat(1001, 5));
//		System.out.println(floatFormat(1231.954f, 10));
//		System.out.println(doubleFormat(1001.954d, 10));
//	}

	/**
	 * 
	 * @param srcNumber : 需要转换的数据
	 * @param formatInt ： 格式化后字符串补0后的位数
	 * @return
	 */
	public static String numberFormat(int srcNumber, int formatInt) {
		String string = "%0" + formatInt + "d";
		return String.format(string, srcNumber);
	}

	/**
	 * 
	 * @param srcFloat    : 需要转换的数据
	 * @param formatCount : 格式化后保留的小数位数
	 * @return
	 */
	public static String floatFormat(float srcFloat, int formatCount) {
		StringBuilder builder = new StringBuilder();
		builder.append("#.");
		for (int i = 1; i <= formatCount; i++) {
			builder.append("0");
		}
		DecimalFormat df = new DecimalFormat(builder.toString());
		return df.format(srcFloat);
	}

	/**
	 * 
	 * @param srcDouble   : 需要转换的数据
	 * @param formatCount : 格式化后保留的小数位数
	 * @return
	 */
	public static String doubleFormat(double srcDouble, int formatCount) {
		StringBuilder builder = new StringBuilder();
		builder.append("#.");
		for (int i = 1; i <= formatCount; i++) {
			builder.append("0");
		}
		DecimalFormat df = new DecimalFormat(builder.toString());
		return df.format(srcDouble);
	}

}
